package cn.jinjimi.app.poster.activity;

import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

import cn.jinjimi.app.R;
import cn.jinjimi.app.bean.BundleKey;
import cn.jinjimi.app.main.extend.BaseActivity;
import cn.jinjimi.app.poster.fragment.PosterContainerFragment;
import cn.jinjimi.base.util.StringUtils;

/**
 * Created by lforxeverc on 16/9/23.
 */

public class PosterListActivity extends BaseActivity implements View.OnClickListener {
    public static final String DELAY = "delay";
    public static final String ROUTER_TYPE_POSTER = "0";
    public static final String ROUTER_TYPE_JINJU = "1";
    @Override
    protected void beforeInitView() {
        setContentView(R.layout.activity_poster_list);
    }

    @Override
    protected void initial() {
        findViewById(R.id.btn_left).setOnClickListener(this);
        String type = getIntent().getStringExtra(BundleKey.TYPE);
        TextView tvTitle = (TextView) findViewById(R.id.tv_title_bar_title);
        if (!StringUtils.isEmpty(type) && type.equals(ROUTER_TYPE_JINJU)) {
            tvTitle.setText(getString(R.string.dujinju));
        }else{
            tvTitle.setText(getString(R.string.poster));
        }
        String delay = getIntent().getStringExtra(DELAY);
        if(delay != null){
            findViewById(R.id.btn_left).postDelayed(new Runnable() {
                @Override
                public void run() {
                    replace();
                }
            }, 500);
        }
        else{
            replace();
        }

    }
    private void replace(){
        if (isFinishing())
            return;

        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.fl_container, new PosterContainerFragment());
        ft.commitAllowingStateLoss();
    }

    @Override
    public void onClick(View v) {
        finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
